import {AjaxUtil, umiRequest, DISCARD_NEW, DISCARD_OLD} from "anti-replay-ajax-util";
import {StorageUtil} from "pzy-storage-util";
import {LocalStorageKey} from "@/utils/SystemConstantUtil";

// 加入请求拦截器(为每个请求加上额外请求头:Authorization)
umiRequest.interceptors.request.use((url, options) => {
    const obj: any = StorageUtil.localOpt.getJson(LocalStorageKey.LoginUser);
    console.log('请求拦截器:', options, obj);
    const customHeader: any = {}
    if (obj?.token) {
        customHeader.Authorization = obj.token;
    }
    const headers = {...options.headers, ...customHeader};
    console.log('headers', headers)
    return (
        {
            url: url,
            options: {...options, headers, interceptors: true},
        }
    );
});

export const ajaxUtilInstance = new AjaxUtil(umiRequest);

// @ts-ignore
export const AntiReplayModel = {DISCARD_NEW, DISCARD_OLD}
